package com.woniu.service.impl;

import com.woniu.mapper.ClassDao;
import com.woniu.mapper.DeptDao;
import com.woniu.mapper.EmpDao;
import com.woniu.mapper.MajorDao;
import com.woniu.pojo.*;
import com.woniu.pojo.Class;
import com.woniu.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ClassServiceImpl implements ClassService {
    @Autowired
    ClassDao classDao;
    @Autowired
    MajorDao majorDao;
    @Autowired
    EmpDao empDao;
    @Autowired
    DeptDao deptDao;

    @Override
    public void add(Class clazz) {
        classDao.insert(clazz);
    }

    @Override
    public void deleteById(Integer id) {
        classDao.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteByIds(Integer[] ids) {
        for (Integer id:ids) {
            classDao.deleteByPrimaryKey(id);
        }
    }

    @Override
    public Class findOne(Integer id) {
        Class clazz = classDao.selectByPrimaryKey(id);
        return clazz;
    }

    @Override
    public void updateById(Class clazz) {
            classDao.updateByPrimaryKeySelective(clazz);
    }

    @Override
    public List<Class> selectByExample(Class clazz) {
        List<Class> classList = classDao.selectByExample1(clazz);
       return classList;
    }

    @Override
    public List<Major> selectMajorAll() {
        List<Major> majorList = majorDao.selectByExample(null);
        return majorList;
    }

    @Override
    public List<Emp> selectEmpByBZR() {
        List<Emp> empList = empDao.selectEmpByBZR();
        return empList;
    }

    @Override
    public List<Dept> selectDeptAll() {
        List<Dept> deptList = deptDao.selectByExample(null);
        return deptList;
    }

    @Override
    public List<Class> selectAll() {
        return classDao.selectByExample(null);
    }

    @Override
    public Class selectOne(Integer id) {
        return classDao.selectByPrimaryKey(id);
    }
    @Override
    public List<Class> selectEmpByTeacherId(Integer uid) {
        ClassExample classExample=new ClassExample();
        ClassExample.Criteria criteria = classExample.createCriteria();
        if(uid!=null&&uid!=0){
            criteria.andEmpIdEqualTo(uid);
        }
        return classDao.selectByExample(classExample);
    }



}
